/**
 * @description Description
 *
 * @author Candy <candy.yan@motionglobal.com>
 * @date  Creation Date 2018/8/10
 */
var docEl = window.document.documentElement,tid;
refreshRem();
function refreshRem() {
	var width = docEl.getBoundingClientRect().width;
	if (width > 540) { // 最大宽度
		width = 540;
	}
	var rem = width / 10;
	docEl.style.fontSize = rem + 'px';
}
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
	$(window).on("orientationchange",function(){
		if(window.orientation == 0)
		{
			refreshRem();
		}
		else
		{
			refreshRem();
		}
	});
} else {
	(function(win) {
		refreshRem();
		win.addEventListener('resize', function() {
			clearTimeout(tid);
			tid = setTimeout(refreshRem, 300);
		}, false);
		win.addEventListener('pageshow', function(e) {
			if (e.persisted) {
				clearTimeout(tid);
				tid = setTimeout(refreshRem, 300);
			}
		}, false);
	})(window);
}

(function ($) {
	var deakSearchInput = $('.header .search-wrapper.desk-tablet-cnt input ');
	deakSearchInput.focus(function () {
		$(this).css({width: '200px'})
	});
	deakSearchInput.blur(function () {
		if (deakSearchInput.val() == '') {
			$(this).css({width: '100px'})
		}
	});
	var mobileMenuWrapper = $('.mobile-menu-wrapper'), mobileMenuShow = false;
	mobileMenuWrapper.hide();
	var mobileMenuToggle = function () {
		mobileMenuShow = !mobileMenuShow;
		if (mobileMenuShow) {
			mobileMenuWrapper.show();
		} else {
			mobileMenuWrapper.hide();
		}
	};
	$('.icon-category, .mobile-cnt .only-search-toggle, .mobile-menu-wrapper .close-btn, .mobile-menu-masking').click(function () {
		mobileMenuToggle();
	});
	$('.mobile-cnt .only-search-toggle').click(function () {
		$('.mobile-cnt .search-wrapper input').focus();
	})
})(jQuery);